package com.car.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.car.entity.CarData;
import com.car.service.CarDataService;
import com.car.mapper.CarDataMapper;
import com.car.vo.CarDataQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Objects;


@Service
public class CarDataServiceImpl extends ServiceImpl<CarDataMapper, CarData>
        implements CarDataService {


    @Resource
    private CarDataMapper carDataMapper;

    @Override
    public Page<CarData> selectPage(CarDataQueryVo carData) {
        LambdaQueryWrapper<CarData> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(carData.getBrandName())) {
            lambdaQueryWrapper.eq(CarData::getBrandName, carData.getBrandName());
        }

        if (StringUtils.hasText(carData.getDate())) {
            lambdaQueryWrapper.eq(CarData::getDate, carData.getDate());
        }

        if (!Objects.isNull(carData.getMinPrice())) {
            lambdaQueryWrapper.ge(CarData::getMinPrice, carData.getMinPrice());
        }

        if (!Objects.isNull(carData.getMaxPrice())) {
            lambdaQueryWrapper.le(CarData::getMaxPrice, carData.getMaxPrice());
        }


        return carDataMapper.selectPage(new Page<>(carData.getPageNum(), carData.getPageSize()), lambdaQueryWrapper);
    }
}




